//
//  BACotySubView.swift
//  BadAir
//
//  Created by D on 2018/3/9.
//  Copyright © 2018年 D. All rights reserved.
//

import UIKit

class BACotySubView: UIView {
    
    private let titleLabel = UILabel()
    private let valueLabel = UILabel()
    private let colorView = UIView()
    private let progressView = UIView()
    
    //    private let pm25View = BACotySubView()
    //    private let pm10View = BACotySubView()
    //    private let O3View = BACotySubView()
    //    private let NO2View = BACotySubView()
    //    private let COView = BACotySubView()
    //    private let SO2View = BACotySubView()
    
    var model: BAAQICityModel? {
        didSet{
            updateData()
        }
    }
    
    
    private func setupUI() {
        
        
        
        let backView = UIView()
        backView.backgroundColor = UIColor.clear
        addSubview(backView)
        
        progressView.layer.cornerRadius = 5
        progressView.addSubview(colorView)
        addSubview(progressView)
        
        titleLabel.setupLabel(ofSize: 10, weight: .black, txtColor: colorBlack)
        valueLabel.setupLabel(ofSize: 10, weight: .black, txtColor: colorBlack)
        addSubview(titleLabel)
        addSubview(valueLabel)
        
        titleLabel.snp.makeConstraints { (make) in
            make.top.left.equalToSuperview()
            
        }
        valueLabel.snp.makeConstraints { (make) in
            make.top.right.equalToSuperview()
        }
        backView.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(10)
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(5)
            make.bottom.equalToSuperview()
        }
        colorView.snp.makeConstraints { (make) in
            make.top.left.bottom.right.equalTo(backView)
        }
        progressView.snp.makeConstraints { (make) in
            make.top.left.bottom.equalTo(backView)
            make.width.equalTo(backView)
        }
    }
    
    private func updateData() {
        
    }
    
    
    
    private func aqiValue(value: String) {
        
        valueLabel.text = value
        let colors =  BAAqiViewModel.aqiValueWithColor(value: value)
        let caLayer = CAGradientLayer().rainbowLayer(color: colors)
        colorView.layer.insertSublayer(caLayer, at: 0)
        
    }
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}
